import { onMounted, ref } from "vue";
import { Alarm } from "./types";
import axios from "axios";

/**
 * 报警数据
 * @returns
 */
export default function useData() {
	const records = ref<Alarm[]>([]);
	const alarms = ref<Alarm[]>([]);
	const breakTime = ref(0);

	const onGetData = async () => {
		const { data } = await axios.get("api/alarms/screen-data");
		if (data.code === 0) {
			const { records: rs, alarms: as, break_time } = data.data;

			records.value = rs;
			alarms.value = as;
			breakTime.value = break_time;
		}
	};

	// 数据初始化
	onMounted(onGetData);

	return {
		records,
		alarms,
		breakTime,
		onGetData,
	};
}
